package com.wl.spring.mvc;


import com.wl.spring.mvc.web.DateConvertor;
import com.wl.spring.mvc.web.MyReqHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
@ComponentScan("com.wl.spring.mvc")
//@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void configureDefaultServletHandling(
            DefaultServletHandlerConfigurer configurer) {
        //开启静态资源访问功能
        configurer.enable();
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
                                                //两个 * 表示任意级数的路径
        registry.addResourceHandler("/uploadHead/**")
                //:file  外部文件路径         /  兼容性更好
                .addResourceLocations("D:/三期课程视频/SpringMVC2 控制和返回");
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new DateConvertor());
    }

    @Override
    //拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyReqHandler())
                //拦截所有资源
                .addPathPatterns("/**");
    }

    @Bean
    MultipartResolver multipartResolver(){
        return new StandardServletMultipartResolver();
    }
}
